{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8cf235de-fa13-4a79-823f-c26681e3f646",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1c2b735a-816f-47ea-a112-f5c61faf9961",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-11-10 20:10\n"
     ]
    }
   ],
   "source": [
    "current_time = datetime.now().strftime(\"%Y-%m-%d %H:%M\")\n",
    "print(current_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "5f40a8f3-22bb-45a0-80f4-9216567e90c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2025-11-10 20:26.csv'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "current_time = datetime.now().strftime(\"%Y-%m-%d %H:%M.csv\")\n",
    "current_time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "7f1ee28a-9a15-4110-92ca-d6df83063fa6",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "目前的思路：\n",
    "    1. 重要与紧急程度的表示：\n",
    "    正半轴：1 - 5\n",
    "    负半轴：-5 - -1\n",
    "    x轴表示重要程度，y轴表示紧急程度\n",
    "\n",
    "    值得一提的是，真正重要的，往往是重要且不紧急的\n",
    "\"\"\"\n",
    "# 需要添加方法，完成任务，修改任务内容，添加任务\n",
    "import pandas as pd\n",
    "\n",
    "class MissionList:\n",
    "    def __init__(self, path=r'MissionList.csv', read_json=False, read_csv=False):\n",
    "        if read_json:\n",
    "            self.list = self.read_json()\n",
    "        elif read_csv:\n",
    "            self.list = self.read_csv(path)\n",
    "        else:\n",
    "            self.list = self.init_list()\n",
    "        self.address = 'D:/MissionList/Misssons/'\n",
    "\n",
    "    def read_json(self, path):\n",
    "        pass\n",
    "\n",
    "    def read_csv(self, path):\n",
    "        try:\n",
    "            df = pd.read_csv(path, encoding='utf-8')\n",
    "            sorted_df = df.sort_values(by=['total', 'importance'], ascending=[False, False])\n",
    "            return sorted_df\n",
    "        except Exception as e:\n",
    "            print(e)\n",
    "\n",
    "    def save_csv(self):\n",
    "        try:\n",
    "            current_time = datetime.now().strftime(\"%Y-%m-%d %H时%M分.csv\")\n",
    "            self.list.to_csv(self.address + current_time, encoding='utf-8', index = False)\n",
    "        except Exception as e:\n",
    "            print(e)\n",
    "\n",
    "    def get_num(self, flag):\n",
    "        name = '重要性' if flag else '紧急性'\n",
    "        while True:\n",
    "            try:\n",
    "                num = int(input(f'{name}(-5-5):'))\n",
    "                if num not in range(-5, 6):\n",
    "                    print('重新输入')\n",
    "                    continue\n",
    "                return num\n",
    "            except Exception as e:\n",
    "                print(e, '\\n重新输入')\n",
    "                continue\n",
    "\n",
    "    def init_list(self):\n",
    "        missions = []\n",
    "        count = 1\n",
    "        while True:\n",
    "            print('任务', count)\n",
    "            mission = input('任务(0 to stop):')\n",
    "            if mission == '0':\n",
    "                break\n",
    "            urgency = self.get_num(0)\n",
    "            importance = self.get_num(1)\n",
    "            total = urgency + importance\n",
    "            missions.append({'mission': mission, 'importance': importance, 'urgency': urgency, 'total': total})\n",
    "            count += 1\n",
    "        df = pd.DataFrame(missions)\n",
    "        sorted_df = df.sort_values(by=['total', 'importance'], ascending=[False, False])\n",
    "        print('任务清单已创建')\n",
    "        return sorted_df\n",
    "\n",
    "    # def show(self):\n",
    "    #     print(f'{\"任务\".ljust(6)} | {\"任务名称\".ljust(25)} | {\"重要性\".ljust(8)} | {\"紧急性\".ljust(8)}')\n",
    "    #     for index, mission in self.list.iterrows():\n",
    "    #         print(f'{str(index+1).ljust(6)} | {mission[\"mission\"].ljust(25)} | {str(mission[\"importance\"]).ljust(8)} | {str(mission[\"urgency\"]).ljust(8)}')\n",
    "    # 问题: 打印始终无法对齐？？？    \n",
    "    def finish_mission(self):\n",
    "        try:\n",
    "            self.show()\n",
    "            index = int(input('所完成任务的编号'))\n",
    "            if index not in self.list.index.tolist():\n",
    "                raise ValueError('编号不存在')\n",
    "            self.list.drop(index,inplace=True)\n",
    "            print('任务', index, '已完成')\n",
    "            self.save_csv()\n",
    "            return True\n",
    "        except Exception as e:\n",
    "            print(e)\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "e47cdcdb-3eac-4caa-84f0-c5a1b82ddc34",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "任务 1\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "任务(0 to stop): 导论project中期任务\t\n",
      "紧急性(-5-5): 3\n",
      "重要性(-5-5): 4\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "任务 2\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "任务(0 to stop): 比特学习一节课\n",
      "紧急性(-5-5): 3\n",
      "重要性(-5-5): 5\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "任务 3\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "任务(0 to stop): 数据结构继续学习\n",
      "紧急性(-5-5): 2\n",
      "重要性(-5-5): 5\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "任务 4\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "任务(0 to stop): 0\n"
     ]
    }
   ],
   "source": [
    "list = MissionList()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "ef041e60-6426-4c86-a437-e345b3b1e113",
   "metadata": {},
   "outputs": [],
   "source": [
    "path = 'D:/MissionList/Misssons/2025-11-10 20 33.csv'\n",
    "list = MissionList(path, read_csv=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "57531e6b-8e45-489e-af7f-57638cf6bdcf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "任务     | 任务名称                      | 重要性      | 紧急性     \n",
      "1      | 比特学习一节课                   | 5        | 3       \n",
      "2      | 数据结构继续学习                  | 5        | 2       \n",
      "3      | 导论project中期任务\t            | 4        | 3       \n"
     ]
    }
   ],
   "source": [
    "list.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6324568f-3ec9-4442-8a2e-25f7560a3238",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:miniconda3]",
   "language": "python",
   "name": "conda-env-miniconda3-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
